package com.yxq.mdt.app.modules.classification.ui;

import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.modules.classification.bean.ClassificationBean;

import java.util.List;

/**
 * @author L
 * @time 2019-10-21
 * @describe 全部分类一级分类列表
 */
public class ClassificationMenuListAdapter extends BaseQuickAdapter<ClassificationBean.ListBeanX, BaseViewHolder> {
    private int checkedPosition = 0;

    public ClassificationMenuListAdapter(int layoutResId, @Nullable List<ClassificationBean.ListBeanX> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ClassificationBean.ListBeanX item) {

        TextView titleView = helper.getView(R.id.menu_tv_name);
        helper.setText(R.id.menu_tv_name, item.getName());
        helper.setVisible(R.id.menu_iv_check, helper.getAdapterPosition() == checkedPosition);
        helper.setBackgroundColor(R.id.menu_root, helper.getAdapterPosition() == checkedPosition ? mContext.getResources().getColor(R.color.white) : mContext.getResources().getColor(R.color.bg_gray));
        if (helper.getAdapterPosition() == checkedPosition) {
            titleView.setTextColor(mContext.getResources().getColor(R.color.color_font_black));
            titleView.getPaint().setFakeBoldText(true);//加粗
        } else {
            titleView.setTextColor(mContext.getResources().getColor(R.color.color_font_gray));
            titleView.getPaint().setFakeBoldText(false);//不加粗
        }
    }

    public void setChecked(int position) {
        this.checkedPosition = position;
        notifyDataSetChanged();
    }
}
